package com.service.permisson;



import com.bpms.common.CommonUtil;
import com.bpms.common.JdbcWorker;
import com.bpms.common.VO;
import com.bpms.common.VOList;
import com.bpms.eai.PackTool;
import com.bpms.esb.IService;
import com.zk.atm.utils.ConstantsAtmp;
/**
 * 菜单树初始化
 * @author menlin
 *
 */
public class Menutreeinit extends PackTool implements IService {

	private String _u = null;
	private VO result = new VO();
	private JdbcWorker jw = null;
	@Override
	public VO exec(VO arg) {
		_u = arg.getAttr("u");
		try {
			jw = new JdbcWorker();
			VOList list = jw.readAll(new VO(), this.splitSql(_u));
			result.setObj(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_VOLIST, list);
			result.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "success");
			result.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "");
		} catch (Exception e) {
			CommonUtil.debug("", e);
		}
		return result;
	}
	
	/**
	 * 拼装sql语句
	 * @param u	用户id
	 * @return 	String
	 */
	private String splitSql(String u){
		StringBuffer sql = new StringBuffer(500);
		sql.append("select atmp_menutree.* from atmp_menutree,");
		sql.append(" (select atmp_permtree.* from atmp_permtree,");
		sql.append(" (select * from");
		sql.append(" (select atmp_role.roleid from");
		sql.append(" (select atmp_userrole.roleid from  atmp_userrole , bpm_user");
		sql.append(" where bpm_user.userid = atmp_userrole.userid and bpm_user.userid='" + u + "')");
		sql.append(" ur , atmp_role where atmp_role.roleid=ur.roleid) role_t, atmp_roleperm");
		sql.append(" where atmp_roleperm.roleid=role_t.roleid) rp");
		sql.append(" where atmp_permtree.permid=rp.permid) tp");
		sql.append(" where tp.treeid = atmp_menutree.autoid");
		return sql.toString();
	}

}
